<?
//inculde即可以使用data数据。本页所有的data数据，倾在controller都处理好
include_once("../../../common/module/checkA.php");
include_once("../../../../config.php");
include_once("../controller/detail-edit.php");
?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="../css/<? echo $theme_folder ?>/user.css" rel="stylesheet" type="text/css"/>
    <?php include ROOT_PATH_.'/controller/common/module/head.php'; ?>
    <?php include 'module/head.php'; ?>
</head>

<body>

<div id="topbar">
    <?php include ROOT_PATH_.'/controller/common/module/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/module/sidebar.php'; ?>
        </div>


        <div id="content">
            <?php $page_title='联系人列表';?>
            <?php include ROOT_PATH_.'/controller/common/module/mod-page-title.php'; ?>





    <div class="detail-box layui-form">


        <div class="detail-boxes">

			<fieldset class="layui-elem-field layui-field-title">
				<legend>订单信息 </legend>
			</fieldset>


			<div class="data">
				<button class="layui-btn  layui-btn-sm"  onclick="save_client('<? echo $detail['name']?>','<? echo $detail['phone']?>')" >保存客户</button>
				<button class="layui-btn  layui-btn-sm" onclick="save_unit('<? echo $detail['shuihao']?>','<? echo $detail['address']?>')" >保存企业</button>


				<?php
				if($detail['order_status'] == 0){
					echo '<a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="config_oder('.$trans_nid.')">出单</a>';
				}
				elseif($detail['order_status'] == 1){
					echo '<a class="layui-btn  layui-btn-sm" href="javascript:;" >已出单</a>';
				}

				if($detail['order_status'] == 0){
					echo '<a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="cancel_oder('.$trans_nid.')">取消订单</a>';
				}
				elseif($detail['order_status'] == 2){
					echo '<a class="layui-btn  layui-btn-sm" href="javascript:;" >订单已取消</a>';
				}
				?>
				<a class="layui-btn  layui-btn-sm" href="export.phpn=<?echo $detail['order_sn'] ?>">下载Excel</a>

			</div>


			<table class="layui-table">
				<colgroup>
					 <col >
				</colgroup>
				<thead>
				<tr>
					<th>客户名称</th>
					<th>税号</th>
					<th>电话</th>
					<th>地址</th>
					<th>邮箱</th>
					<th>状态</th>
					<th>业务员</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody>

					<tr  >
						<td><? echo $detail['name']?></td>
						<td>[<? echo $detail['shuihao']?>]</td>
						<td><? echo $detail['phone']?></td>
						<td><? echo $detail['address']?></td>
						<td><? echo $detail['mailbox']?></td>
						<td><? echo $detail['status']?></td>
						<td><? echo $emp['name']?></td>
						<td>

						</td>
					</tr>
				</tbody>

			</table>
			<textarea placeholder="备注" id="remark" class="layui-textarea remark" > <? echo $detail['remark']?></textarea>


			<fieldset class="layui-elem-field layui-field-title">
				<legend> 订单汇总</legend>
			</fieldset>

			<table class="layui-table">

				<colgroup>
					<col width="100">
					<col width="100">
					<col>
				</colgroup>
				<thead>
				<tr>
					<th>品类数目</th>
					<th>商品总数</th>
					<th>总价</th>
					<th>税后价</th>
					<th>汇率</th>
					<th>下单时间</th>
					<th>确认时间</th>
					<th>收款时间</th>
				</tr>
				</thead>
				<tbody>

				<tr>
					<td > <? echo count($goods_list)?>
					</td>
					<td>
						<?
						$goodsCount = 0;
						foreach($goods_list as $val){
							$goodsCount = $goodsCount + $val['goods_number'];
						}
						echo $goodsCount; ?>
					</td>
					<td><? echo $detail['price']?></td>
					<td><? echo $detail['price']*$detail['shuilv']*$detail['huilv']?></td>

					<td><? echo $detail['huilv']?></td>
					<td><? echo $detail['add_date']?></td>
					<td><? echo $detail['deliver_date']?></td>
					<td>
						<div class="layui-input-inline">
							<input type="text" class="layui-input" value="<? echo $detail['collection_date']?>"  id="collection_date" placeholder="yyyy-MM-dd HH:mm:ss">
						</div>
					</td>
				</tr>

				</tbody>
			</table>


			<fieldset class="layui-elem-field layui-field-title">
				<legend> 产品清单</legend>
			</fieldset>


        	<table class="layui-table">
              <colgroup>
                <col>
              </colgroup>
              <thead>
              	
                <tr>
                  <th>商品名字</th>
                  <th>商品型号</th>
                  <th>商品价格</th>
                  <th>委币价格</th>
                  <th>商品数量</th>
                  <th>价格小结</th>
                  <th>优惠活动</th>
                </tr>
              </thead>
              <tbody>
              <?php 
			  foreach($goods_list as $val){
			  ?>
                <tr>
                  <td><?php echo $val['name'];?></td>
                  <td><?php echo $val['model'];?></td>
                  <td><?php echo $val['price'];?></td>
                  <td><?php echo $val['price']*$detail['huilv'];?></td>
                  <td><?php echo $val['number'];?></td>
                  <td><?php echo $val['number']*$val['price'];?></td>
                  <td><?php echo $val['youhuihuodong'];?></td>
                </tr>
              <?php 
			  }
			  ?>
              	<tr>

                </tr>
              </tbody>
            </table>
        </div>

		<div class="function">

            <!--//TODO 根据状态，显示隐藏某些按钮。-->
			<a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="config_oder('<? echo $detail['nid']?>')">确认订单</a>
			<a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="config_oder('<? echo $detail['nid']?>')">取消订单</a>
			<a class="layui-btn  layui-btn-sm" href="javascript:;" onclick="config_oder('.$trans_nid.')">订单发货</a>
			<a class="layui-btn  layui-btn-sm" href="/api/make-order-excel.php?sn=<?echo $detail['order_sn'] ?>">导出表格</a>


		</div>
    </div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?>

<script>

	layui.use('laydate', function(){
		var laydate = layui.laydate;
	//日期时间选择器
	laydate.render({
		elem: '#collection_date'
		,type: 'datetime'
	});
	});
	function save_client (name,phone) {

		con=confirm("确认保存客户?");
		if(con==true){
			$.ajax({
				type:"POST",
				url:"ajax_save.php",
				dateType:"json",
				data:{"act":'client',"name":name,"phone":phone},
				dataType:"json",
				beforeSend: function () {
					layer.msg('正在检查状态中');
				},
				success:function(data){

					if(data.error == 1){
						layer.msg(data.message, {icon: 2});
					}
					else if(data.error == 0){
						layer.msg(data.message, {icon: 1});

					}
				}
			})

		}

	}

	function save_unit (shuihao,address) {

		con=confirm("确认保存企业?");
		if(con==true){
			$.ajax({
				type:"POST",
				url:"ajax_save.php",
				dateType:"json",
				data:{"act":'unit',"shuihao":name,"address":address},
				dataType:"json",
				beforeSend: function () {
					layer.msg('正在检查状态中');
				},
				success:function(data){

					if(data.error == 1){
						layer.msg(data.message, {icon: 2});
					}
					else if(data.error == 0){
						layer.msg(data.message, {icon: 1});

					}
				}
			})

		}

	}

 
    function cancel_oder (id) {

        con=confirm("确认取消订单?");
        if(con==true){

			if(!id > 0 ){
				layer.msg('请刷新后再操作！');
				return false;
			}

			$.ajax({
				type:"POST",
				url:"cancel.php",
				dateType:"json",
				data:{"nid":id},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');

               	},
				success:function(data){

						if(data.error == 1){
							layer.msg(data.content, {icon: 2});
						}
						else if(data.error == 0){
							layer.msg(data.content, {icon: 1});

						}
						window.location.reload();//刷新当前页面.
				}
			})


        }

    }
	
	
	
    function config_oder (id) {
		var collection_date = $('#collection_date').val();
		var remark = $('#remark').val();
		if(collection_date == ""){
			layer.msg('请选择付款时间');
			return;
		}
        con=confirm("确认出单吗?");
        if(con==true){
				
			if(!id > 0 ){
				layer.msg('请刷新后再操作！');
				return false;
			}              

			$.ajax({
				type:"POST",
				url:"config_order.php",
				dateType:"json",
				data:{"nid":id,"collection_date" : collection_date,"remark" : remark},
                dataType:"json",
				beforeSend: function () {
                      layer.msg('正在检查状态中');
                           
               	}, 
				success:function(data){
								
						if(data.error == 1){
							layer.msg(data.content, {icon: 2}); 
						}
						else if(data.error == 0){
							layer.msg(data.content, {icon: 1});
							window.location.reload();//刷新
						}

				}
			})	
    

        }

    }

</script>

</body>
</html>
